<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  /*
   *用户输入一个整数n：求1! + 2! + 3! + 4! + …… + n!的和
   */
  
  //求阶乘
  function f(num){
    if(num == 1){
      return 1;
    }
    return num * f(num-1);
  }

  //主程序
  var num = parseInt(prompt("请输入一个数字计算阶乘"));
  var sum = 0;
  for(var i = 1; i<= num; i++){
    sum += f(i);
  }
  alert(''.concat('阶乘结果和为：',sum));
</script>
</html>